<ul class="nav navbar-nav float-right">

    <li class="dropdown dropdown-user nav-item">
        <a class="dropdown-toggle nav-link" href="javascript:void(0);">
            <span class="dark-mode-switcher">
                <i class="feather icon-moon" title="夜间模式"></i>
            </span>
        </a>
    </li>
    <li class="dropdown dropdown-user nav-item">
        <a class="dropdown-toggle nav-link" href="javascript:void(0);">
            <span class="trash-cache">
                <i class="feather icon-trash-2" title="清空缓存"></i>
            </span>
        </a>
    </li>
</ul>
<script type="text/javascript">
(function () {
    try {
        (function() {
	    	var storage = localStorage || {setItem:function () {}, getItem: function () {}},
	        darkMode = Dcat.darkMode,
	        key = 'dcat-admin-theme-mode',
	        mode = storage.getItem(key),
	        icon = $('.dark-mode-switcher i');

		    function switchMode(dark) {
		        if (dark) {
		            icon.addClass('icon-sun').removeClass('icon-moon');
		            darkMode.display(true);
		            return;
		        }

		        darkMode.display(false);
		        icon.removeClass('icon-sun').addClass('icon-moon');
		    }

		    if (mode === 'dark') {
		        switchMode(true);
		    } else if (mode === 'def') {
		        switchMode(false)
		    }

		    $('.dark-mode-switcher').off('click').on('click', function () {
		        icon.toggleClass('icon-sun icon-moon');

		        if (icon.hasClass('icon-moon')) {
		            switchMode(false);

		            storage.setItem(key, 'def');

		        } else {
		            storage.setItem(key, 'dark');

		            switchMode(true)
		        }
		    })
		    $('.trash-cache').off('click').on('click', function () {
		        $.ajax({
		        	url:"{{url('admin/cache/flush')}}",
		        	dataType:"json",
		        	success:function(res){
		        		if(res.code<200){
		        			Dcat.success(res.msg);
		        		}
		        	}
		        })
		    })
		})()
    } catch (e) {
        console.error(e)
    }
})()
</script>